package com.taxis.action;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.opensymphony.xwork2.ActionSupport;
import com.taxis.model.Usuario;
import com.taxis.service.UsuarioDaoService;
import java.util.Map;

@SuppressWarnings("serial")
public class LoginAction extends ActionSupport implements ServletRequestAware {

	private String usuario;
	private String password;
	private HttpServletRequest request;
	private static final String FAILURE = "failed";

	public void setServletRequest(HttpServletRequest httpServletRequest) {
		this.request=httpServletRequest;
	}

	public String getUsuario() {
		return usuario;
	}

	public void setUsuario(String usuario) {
		this.usuario = usuario;
	}

	public void setPassword(String password) {
	/*	this.password = new com.taxis.common.EncryptText().encrypt(password);*/
		this.password = password;
	}

	public String execute() throws Exception {
		UsuarioDaoService usuarioService = new UsuarioDaoService();
		Usuario user = usuarioService.findByUsernameAndPassword(usuario, password);

		if (user != null) {
			request.getSession(true).setAttribute("usuario", user);
			
			return SUCCESS;
	}
			
		 else {
			addActionError("Login inv&aacute;lido");
			return FAILURE;
		}
	}
}
